header {
package com.aote.expression.antlr;
import com.browsesoft.htmlcomponent.HTMLBasicComponent;
import com.aote.expression.ParamProcessorFactory;
import com.aote.expression.function.StringFunctionFactory;
import java.util.Map;
import java.util.List;
import java.util.LinkedList;
import java.util.Collection;
import org.w3c.dom.Element;
}

class MultiValueExpression extends Parser ;
{
	private String getParamString(String param) {
		int len = param.length();
		return param.substring(1, len - 1);
	}

    private Collection process(String param,Map attrs,HTMLBasicComponent component,Element config)
    {
        return ParamProcessorFactory.getInstance().process(param,attrs,component,config);
    }
}

expression [Map attrs,HTMLBasicComponent component,Element config]
returns [Collection result=null]
{
	Collection b;
	
}
	: b=function[attrs,component,config] {result=b;}
	| p:PARAMS {result=process(getParamString(p.getText()),attrs,component,config);}
	;
	
function [Map attrs,HTMLBasicComponent component,Element config]
returns [Collection result=null]
{
	List pl;
}
	: (id:ID LEFT pl=paramList[attrs,component,config] RIGHT) {result=StringFunctionFactory.getInstance().invoke(id.getText(), pl);}
	;
	
paramList [Map attrs,HTMLBasicComponent component,Element config]
returns [List result=new LinkedList()]
{
	Object p;
	Object p1;
}
	: p=paramItem[attrs,component,config] {result.add(p);} (COMMA p1=paramItem[attrs,component,config] {result.add(p1);})*
	;
	
paramItem [Map attrs,HTMLBasicComponent component,Element config]
returns [Object result=null]
{
	Collection b;
}
	: b=expression[attrs,component,config] {result=b;}
	| s:STRING {result=getParamString(s.getText());}
	| v:NUMBER {result=new Double(v.getText());}
	;
	
class MultiValueLexer extends Lexer; 
	
WS: ' '
 	{$setType(Token.SKIP);} 
 	;

PARAMS
	: '#' (~'#')+ '#'
	;

LEFT
	: '('
	;

RIGHT
	: ')'
	;

COMMA
	: ','
	;

NUMBER
	: ('0'..'9')+(('.')('0'..'9')+)?
	;

ID
	: ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
	;

STRING
	: '"' (~('#' | '"' | '.' | '\u0080'..'\ufffe') | '\u0080'..'\ufffe')+ '"'
	;
